package com.anuprayog.treasureloot;

import android.media.AudioManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;

/**
 * @author amit
 * This activity is where the user is redirected after the game
 * gets over showing the score the user made
 */
public class GameOverActivity extends Activity {

		private ImageView imageview2, imageview3, imageview4, imageview5, imageview6, imageview7;
		
		public static String SOUND_STATE = "";
		
		public static String EXTRA_SCORE = "";
		public static String HIGHSCORE = "";
		
		public String score;
		public String soundState;
		
		@Override
		protected void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			setContentView(R.layout.activity_game_over);
			
			setVolumeControlStream(AudioManager.STREAM_MUSIC);
			
			imageview2 = (ImageView) findViewById(R.id.imageView2);
			imageview3 = (ImageView) findViewById(R.id.imageView3);
			imageview4 = (ImageView) findViewById(R.id.imageView4);
			imageview5 = (ImageView) findViewById(R.id.imageView5);
			imageview6 = (ImageView) findViewById(R.id.imageView6);
			imageview7 = (ImageView) findViewById(R.id.imageView7);
			
			Intent i = getIntent();
			
			score = i.getStringExtra(ExplosionActivity.HIGH_SCORE);
			
			soundState = i.getStringExtra(ExplosionActivity.SOUND_OFF_STRING);
			
			if (score.charAt(0) == '0'){
				imageview2.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.zero));
			} else if (score.charAt(0) == '1'){
				imageview2.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.one));
			} else if (score.charAt(0) == '2'){
				imageview2.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.two));
			} else if (score.charAt(0) == '3'){
				imageview2.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.three));
			} else if (score.charAt(0) == '4'){
				imageview2.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.four));
			} else if (score.charAt(0) == '5'){
				imageview2.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.five));
			} else if (score.charAt(0) == '6'){
				imageview2.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.six));
			} else if (score.charAt(0) == '7'){
				imageview2.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.seven));
			} else if (score.charAt(0) == '8'){
				imageview2.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.eight));
			} else if (score.charAt(0) == '9'){
				imageview2.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.nine));
			} 
			
			if (Integer.parseInt(score)>9){
				if (score.charAt(1) == '0'){
					imageview3.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.zero));
				} else if (score.charAt(1) == '1'){
					imageview3.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.one));
				} else if (score.charAt(1) == '2'){
					imageview3.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.two));
				} else if (score.charAt(1) == '3'){
					imageview3.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.three));
				} else if (score.charAt(1) == '4'){
					imageview3.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.four));
				} else if (score.charAt(1) == '5'){
					imageview3.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.five));
				} else if (score.charAt(1) == '6'){
					imageview3.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.six));
				} else if (score.charAt(1) == '7'){
					imageview3.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.seven));
				} else if (score.charAt(1) == '8'){
					imageview3.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.eight));
				} else if (score.charAt(1) == '9'){
					imageview3.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.nine));
				} 
			}
			
			if (Integer.parseInt(score)>99){
				if (score.charAt(2) == '0'){
					imageview4.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.zero));
				} else if (score.charAt(2) == '1'){
					imageview4.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.one));
				} else if (score.charAt(2) == '2'){
					imageview4.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.two));
				} else if (score.charAt(2) == '3'){
					imageview4.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.three));
				} else if (score.charAt(2) == '4'){
					imageview4.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.four));
				} else if (score.charAt(2) == '5'){
					imageview4.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.five));
				} else if (score.charAt(2) == '6'){
					imageview4.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.six));
				} else if (score.charAt(2) == '7'){
					imageview4.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.seven));
				} else if (score.charAt(2) == '8'){
					imageview4.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.eight));
				} else if (score.charAt(2) == '9'){
					imageview4.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.nine));
				} 
			}
			
			if (Integer.parseInt(score)>999){
				if (score.charAt(3) == '0'){
					imageview5.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.zero));
				} else if (score.charAt(3) == '1'){
					imageview5.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.one));
				} else if (score.charAt(3) == '2'){
					imageview5.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.two));
				} else if (score.charAt(3) == '3'){
					imageview5.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.three));
				} else if (score.charAt(3) == '4'){
					imageview5.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.four));
				} else if (score.charAt(3) == '5'){
					imageview5.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.five));
				} else if (score.charAt(3) == '6'){
					imageview5.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.six));
				} else if (score.charAt(3) == '7'){
					imageview5.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.seven));
				} else if (score.charAt(3) == '8'){
					imageview5.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.eight));
				} else if (score.charAt(3) == '9'){
					imageview5.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.nine));
				} 
			}
			
			if (Integer.parseInt(score)>9999){
				if (score.charAt(4) == '0'){
					imageview6.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.zero));
				} else if (score.charAt(4) == '1'){
					imageview6.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.one));
				} else if (score.charAt(4) == '2'){
					imageview6.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.two));
				} else if (score.charAt(4) == '3'){
					imageview6.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.three));
				} else if (score.charAt(4) == '4'){
					imageview6.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.four));
				} else if (score.charAt(4) == '5'){
					imageview6.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.five));
				} else if (score.charAt(4) == '6'){
					imageview6.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.six));
				} else if (score.charAt(4) == '7'){
					imageview6.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.seven));
				} else if (score.charAt(4) == '8'){
					imageview6.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.eight));
				} else if (score.charAt(4) == '9'){
					imageview6.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.nine));
				} 
			}
			
			if (Integer.parseInt(score)>99999){
				if (score.charAt(5) == '0'){
					imageview7.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.zero));
				} else if (score.charAt(5) == '1'){
					imageview7.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.one));
				} else if (score.charAt(5) == '2'){
					imageview7.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.two));
				} else if (score.charAt(5) == '3'){
					imageview7.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.three));
				} else if (score.charAt(5) == '4'){
					imageview7.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.four));
				} else if (score.charAt(5) == '5'){
					imageview7.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.five));
				} else if (score.charAt(5) == '6'){
					imageview7.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.six));
				} else if (score.charAt(5) == '7'){
					imageview7.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.seven));
				} else if (score.charAt(5) == '8'){
					imageview7.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.eight));
				} else if (score.charAt(5) == '9'){
					imageview7.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.nine));
				} 
			}
			
		}
		
		@Override
		public boolean onCreateOptionsMenu(Menu menu) {
			// Inflate the menu; this adds items to the action bar if it is present.
			getMenuInflater().inflate(R.menu.game_over, menu);
			return true;
		}
		
		public void goBack(View view) {
	        Intent intent = new Intent(this, MainActivity.class);
	        intent.putExtra(SOUND_STATE, soundState);
	        startActivity(intent);
	        finish();
	    }
		
		@Override
	    public void onBackPressed() {
	  
			Intent intent = new Intent(this, MainActivity.class);
	        intent.putExtra(SOUND_STATE, soundState);
	        startActivity(intent);
	        finish();

	  
	     }

	}
